package com.weigj.controller;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.weigj.model.CarInfo;
import com.weigj.model.Client;
import com.weigj.model.ReserveHour;
import com.weigj.service.DeptAppService;
import com.weigj.service.impl.DeptAppServiceImpl;

public class ReserveHourController extends Controller{
	
	public void queryReserve(){
		Integer reserHourstate=getParaToInt("reserveHour.reserveState");
		Client client=getSessionAttr("client");
		if(client!=null){
			List<ReserveHour> hours=ReserveHour.dao.queryRHByState(client.getBigDecimal("clieid").longValue(), reserHourstate);
			setAttr("hours", hours);
			render("/myorder.jsp");
		}else{
			render("/index.jsp");
		}
		
	}
	
	//
	public void reserveConverHt(){
		String orderId=getPara("orderId");
		DeptAppService deptAppService=new DeptAppServiceImpl();
		deptAppService.sendCar("30", orderId, null,null);
		render("/searchHour.jsp");
	}
	
	//查询
	public void queryOneById(){
		Long id=getParaToLong("id");
		ReserveHour hour=ReserveHour.dao.findById(id);
		setAttr("hour", hour);
		if(hour.getBigDecimal("reserveState").intValue()==0){
			render("/order_quxiao.jsp");
		}else if(hour.getBigDecimal("reserveState").intValue()==1){
			render("/order_yuyue.jsp");
		}else if(hour.getBigDecimal("reserveState").intValue()==2){
			//已完成预订单显示的是合同信息
			Record record=ReserveHour.dao.queryOneCont(hour.getBigDecimal("id").longValue());
			setAttr("hourCont", record);
			render("/order_finish.jsp");
		}
	}
	
	//取消订单
	public void reserveHourCancel(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Long id=getParaToLong("id");
		String cancelDoc=getPara("cancelDoc");
		ReserveHour reserveHour=new ReserveHour().findById(id);
		//更新赋值
		CarInfo car=CarInfo.dao.queryCarInfo(reserveHour.getStr("carNum"));
		car.set("carState", "待租");
		car.update();
		reserveHour.set("cancelDoc", cancelDoc);
		reserveHour.set("cancelDate", sdf.format(new Date()));
		reserveHour.set("reserveState", 0);
		reserveHour.update();
		render("/index.jsp");
	}
	
}
